<?php
class MWidget {
    private $_id;
    protected $_title;
    protected $_contentUrl;
    protected $_template;
    public $canMove = true;
    public $canToggle = true;
    public $canRefresh = true;
    
    public function __construct($title, $contentUrl = NULL, $template = NULL) {
        $this->_title = $title;
        $this->_id = isset($this->_title)?MPublisher::hash($this->_title):MPublisher::hash(uniqid());
        $this->_contentUrl = $contentUrl;
        $this->_template = (isset($template))?$template:MD_LIB.DS.'views'.DS.'widgetTemplate.php';
    }
    
    public function render(){
        MPackage::import('jquery-ui');
        MPackage::import('mandrill-widget');
        ob_start();
        require($this->_template);
        $widget = ob_get_contents();
        ob_end_clean();
        return $widget;
    }
    
    public function getId() {
        return $this->_id;
    }
        
    public function getTitle() {
        return $this->_title;
    }

    public function setTitle($_title) {
        $this->_title = $_title;
    }
    
    public function getContentUrl() {
        return $this->_contentUrl;
    }

    public function setContentUrl($_contentUrl) {
        $this->_contentUrl = $_contentUrl;
    }

    public function getTemplate() {
        return $this->_template;
    }

    public function setTemplate($_template) {
        $this->_template = $_template;
    }
    
    public function __toString() {
        return $this->render();
    }
}
?>
